/**
 * Copyright &copy; 2012-2016 <a href="https://git.oschina.net/zdw2016/webbase5">Webbase</a> All rights reserved.
 */
package com.foreveross.webbase.project.web;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.foreveross.webbase.common.config.Global;
import com.foreveross.webbase.common.persistence.Page;
import com.foreveross.webbase.common.web.BaseController;
import com.foreveross.webbase.common.utils.StringUtils;
import com.foreveross.webbase.project.entity.SysSpSoftware;
import com.foreveross.webbase.project.service.SysSpSoftwareService;

/**
 * 软件管理Controller
 * @author yangwanli
 * @version 2017-03-13
 */
@Controller
@RequestMapping(value = "${adminPath}/project/sysSpSoftware")
public class SysSpSoftwareController extends BaseController {

	@Autowired
	private SysSpSoftwareService sysSpSoftwareService;
	
	@RequiresPermissions("project:sysSpSoftware:view")
	@RequestMapping(value = {"list", ""})
	public String list(SysSpSoftware sysSpSoftware) {
		Page<SysSpSoftware> page = sysSpSoftwareService.findPage(new Page<SysSpSoftware>(request(), response()), sysSpSoftware); 
		attr("page", page);
		return "project/sysSpSoftwareList";
	}
	@RequiresPermissions("project:sysSpSoftware:view")
	@RequestMapping("objj")
	@ResponseBody
	public List<SysSpSoftware> listSoftware(SysSpSoftware sysSpSoftware) {
		List<SysSpSoftware> findObjj = sysSpSoftwareService.findList(sysSpSoftware);
		return findObjj;
		
	}
	
	@RequiresPermissions("project:sysSpSoftware:view")
	@RequestMapping("form")
	public String form(String id) {
		if(StringUtils.isNotEmpty(id)) {
			SysSpSoftware sysSpSoftware=sysSpSoftwareService.get(id);
			attr("sysSpSoftware", sysSpSoftware);
		} else {
			attr("sysSpSoftware", new SysSpSoftware());
		}
		return "project/sysSpSoftwareForm";
	}

	@RequiresPermissions("project:sysSpSoftware:edit")
	@RequestMapping("save")
	public String save(SysSpSoftware sysSpSoftware, RedirectAttributes redirectAttributes) {
		
		sysSpSoftwareService.save(sysSpSoftware);
		addMessage(redirectAttributes, "保存软件成功");
		return "redirect:"+Global.getAdminPath()+"/project/sysSpSoftware/?repage";
	}
	
	@RequiresPermissions("project:sysSpSoftware:edit")
	@RequestMapping("delete")
	public String delete(@RequestParam String id, RedirectAttributes redirectAttributes) {
		sysSpSoftwareService.delete(id);
		addMessage(redirectAttributes, "删除软件成功");
		return "redirect:"+Global.getAdminPath()+"/project/sysSpSoftware/?repage";
	}

}